home *** CD-ROM | disk | FTP | other *** search
- Path: telepost.no!usenet
- From: Carsten Arnholm <ca@sesam.dnv.no>
- Newsgroups: comp.lang.c++
- Subject: Re: Linking Fortran 77 with C++
- Date: 14 Feb 1996 16:21:53 GMT
- Organization: DNV
- Message-ID: <4ft271$q5a@nms.telepost.no>
- References: <4fsfi4$gqd@ulke.hiMolde.no>
- NNTP-Posting-Host: hugin.sesam.dnv.no
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1 (Windows; I; 32bit)
-
- arildh@himolde.no (Arild Hoff) wrote:
- >I am developing a C++ application that must be linked together with
- >existing Fortran 77 code.
- >I don't want to change the Fortran code because it is very large and
- >working well.
- >
- >My question is : Does anybody know about a Fortran compiler which can
- >compile the Fortran 77 code to obj-files that can be linked with my C++
- >obj-files using the Borland 4.5 C++ linker ????
- >
- >I hope to get this work both under DOS and Windows.
- >
- >Please answer by e-mail : arildh@himolde.no
- >
- >
- >Arild Hoff
- >
-
-
- I also have the same situation: a large amount of tested F77 code which
- is being used in F77 programs, and which I want to re-use within a C++ program.
-
- This is fairly easy with MS Visual C++ 4.0 and MS Fortran Powerstation (both
- are 32 bit compilers for Windows 95/NT).
-
- As an experiment, I wanted to do basically the same within a 16 bit Windows 3.1
- environment, using Borland C++ 4.0 (somewhat old now).
-
- I found that the following worked, at least on an experimental level:
-
- 1. Download the f2c (FORTRAN-to-C) conversion program from the Web.
- Look at: http://www.fortran.com/fortran/free.html
- It is possible to get both binaries and source
-
- 2. Write a little wrapper program in Borland C++ which
- a: takes the name of a FORTRAN file as input
- b: calls the f2c program, using a system("f2c [options] <fortran-file>") call.
- This will generate a C-file. Notice that subroutine names are converted to lowercase
- with a trailing underscore, and that CHARACTERs are converted to char* with an additional
- int (string length value) at the end of the call.
- c: calls the bcc (Borland command-line compiler), using a system("bcc [options] <c-file>")
- This will generate a obj-file compatible with your system.
- d: deletes the C-file using a remove(<C-file>)
- You should consider the C-file as hidden "assembler code", because it is not readable
- by humans, especially if you use Fortran IO (PRINT,READ,WRITE)
-
- Now you have a free 16 bit FORTRAN compiler compatible with Borland !
- I believe it will run under both DOS and Windows 3.1.
-
- 3. Integrate your own FORTRAN compiler into the IDE of Borland, by declaring it as a translator
- tool which translates from .f to .obj files. I think this is done via a Tools->customize ..
- menu in Borland C++ 4.0, but I don't know version 4.5
- Make sure that the text editor also is default viewer for .f files.
-
- 4. You should now be able to mix .f and .cpp files in your Borland projects.
- When you make/build your software, borland C++ will compile your C++ code, and your
- FORTRAN compiler will compile the .f files. It works !
-
- 5. If you want to be really clever, you could make your C++ code portable between different
- compilers/operating systems. To get ideas, I have some contributions on the Usenet. To find
- these, use the AltaVista search engine at http://www.altavista.digital.com/
- select Usenet and search for my name: Arnholm
- There are several articles.
-
- another idea is to go directly to one of the articles at:
-
- http://ww2.altavista.digital.com/cgi-bin/news?msg@1364@comp%2elang%2efortran
-
- Good luck,
-
- Carsten Arnholm
-
-
-
-